package com.ruoyi.tenant;

/**
 * 租户上下文持有类，使用ThreadLocal保证线程安全
 */
public class TenantContext {
    private static final ThreadLocal<String> CURRENT_TENANT = new ThreadLocal<>();

    public static void setCurrentTenant(String tenantId) {
        CURRENT_TENANT.set(tenantId);
    }

    public static String getCurrentTenant() {
        return CURRENT_TENANT.get();
    }

    // 关键：请求处理完成后必须清理，防止内存泄漏和后续请求数据污染
    public static void clear() {
        CURRENT_TENANT.remove();
    }
}
